//
// Created by Bili_TianX_Computer on 2021/7/10.
//

#include "User.h"

User::User(const QString &name, const QString &account, const QString &password, bool isAdmin) :
        name(name),
        account(account),
        password(password),
        isAdmin(isAdmin)
{}

User::User(QJsonObject obj) :
        name(obj["name"].toString()),
        account(obj["account"].toString()),
        password(obj["password"].toString()),
        isAdmin(obj["isAdmin"].toBool())
{}

QJsonObject User::toJsonObject() const
{
    QJsonObject obj;
    obj.insert("name", name);
    obj.insert("account", account);
    obj.insert("password", password);
    obj.insert("isAdmin", isAdmin);
    return obj;
}

bool User::operator==(const User &rhs) const
{
    return name == rhs.name &&
           account == rhs.account &&
           password == rhs.password &&
           isAdmin == rhs.isAdmin;
}

bool User::operator!=(const User &rhs) const
{
    return !(rhs == *this);
}
